package Controller;
import java.awt.Graphics2D;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.*;

import com.itextpdf.text.*;

import java.io.FileOutputStream;
import java.io.IOException;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import com.itextpdf.text.pdf.*;


public class PDF {

	/**
	 * @param args
	 * @throws DocumentException 
	 * @throws FileNotFoundException 
	 * @throws MessagingException 
	 * @throws AddressException 
	 */
	 //public static void main(String[] args) throws FileNotFoundException, DocumentException, AddressException, MessagingException {
		// TODO Auto-generated method stub
		//example main
	private static int[] x=new int[72];
	private static int[] y=new int[72];
	private static int[] d=new int[72];
	private static int[] flag=new int[72];
	int i=0;
	int size;
	
	public PDF(){
		/*Document document = new Document(PageSize.A4, 50, 50, 50, 50);
		PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("C:/TC/Report.pdf"));
		document.open();*/
	}
		String str="Order Report";
		String str1="Complaint Report"; 
		String str2="Maintnance Report";
		String str4="worker List";
		String str5 ="Status Picture";
		String text="Some Report Text";
		/*int[] x = {0,1,2}; 
		int[] y = {0,6,7};
		int[] d = {1,0,2};*/
		//int size=8;
		/*writeOrderReport(document,str,text);
		writeComplaintReport(document,str1,text);
		writeMaintnanceReport(document,str2,text);
		writeWorkerList(document,str4);
		document.newPage();
		writeStatusPic(document,str5,writer,x,y,d,size);*/
		
		
		/*Mail m = new Mail();

		String mailTo = "adimalca50@gmail.com";
		String mailCc = "vcp.grp11@gmail.com";
		String mailFrom = "HanCal_Costumer_Service"; 
		String mailSubject = "Email from Java";
		String mailText = "This is an email from Java";
		//m.sendEmail(mailTo,mailCc,mailFrom, mailSubject,mailText);*/

	//}
		
		
	
	
	
	public static void writeOrderReport (Document document,String str,String str2) throws DocumentException
	{
		  Paragraph title1 = new Paragraph(str,FontFactory.getFont(FontFactory.COURIER,16, Font.BOLD, new CMYKColor(0, 255, 255,17)));
	      Paragraph paragraph1 = new Paragraph();
	      paragraph1.setSpacingBefore(50);
	      title1.setAlignment(Element.ALIGN_CENTER);
	      paragraph1.add(title1);
	      document.add(paragraph1);
	      document.add(new Paragraph(str2,FontFactory.getFont(FontFactory.COURIER, 14, Font.NORMAL)));
	      //document.newPage();
	      document.close();
	        
	}
	
	public static void writeComplaintReport (Document document,String str,String str2) throws DocumentException
	{
		  Paragraph title1 = new Paragraph(str,FontFactory.getFont(FontFactory.COURIER,16, Font.BOLD, new CMYKColor(0, 255, 255,17)));
	      Paragraph paragraph1 = new Paragraph();
	      paragraph1.setSpacingBefore(50);
	      title1.setAlignment(Element.ALIGN_CENTER);
	      paragraph1.add(title1);
	      document.add(paragraph1);
	      document.add(new Paragraph(str2,FontFactory.getFont(FontFactory.COURIER, 14, Font.NORMAL)));
	      //document.newPage();
	      document.close();
	}
	
	public static void writeMaintnanceReport (Document document,String str,String str2) throws DocumentException
	{
		  Paragraph title1 = new Paragraph(str,FontFactory.getFont(FontFactory.COURIER,16, Font.BOLD, new CMYKColor(0, 255, 255,17)));
	      Paragraph paragraph1 = new Paragraph();
	      paragraph1.setSpacingBefore(50);
	      title1.setAlignment(Element.ALIGN_CENTER);
	      paragraph1.add(title1);
	      document.add(paragraph1);
	      document.add(new Paragraph(str2,FontFactory.getFont(FontFactory.COURIER, 14, Font.NORMAL)));
	      //document.newPage();
	      document.close();
	}
	
	public static void writeWorkerList (Document document,String str) throws DocumentException
	{
		
		  Paragraph title1 = new Paragraph(str,FontFactory.getFont(FontFactory.COURIER,16, Font.BOLD, new CMYKColor(0, 255, 255,17)));
	      Paragraph paragraph1 = new Paragraph();
	      paragraph1.setSpacingBefore(50);
	      title1.setAlignment(Element.ALIGN_CENTER);
	      paragraph1.add(title1);
	      document.add(paragraph1);
	      

	     PdfPTable table = new PdfPTable(3);

	      PdfPCell c1 = new PdfPCell(new Phrase("Header1"));   
	      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
	      table.addCell(c1);
	      PdfPCell c2 = new PdfPCell(new Phrase("Header2"));
	      c2.setHorizontalAlignment(Element.ALIGN_CENTER);
	      table.addCell(c2);
	      PdfPCell c3 = new PdfPCell(new Phrase("Header3"));
	      c3.setHorizontalAlignment(Element.ALIGN_CENTER);
	      table.addCell(c3);
	      table.addCell("1.1");
	      table.addCell("1.2");
	      table.addCell("1.3");
	      table.setSpacingBefore(10f);
	      document.add(table);
	      document.close();
	}
	
	public void setLevel(int a)
	{
		x[i]=a;
	}
	
	public void setRaw(int a)
	{
		y[i]=a;
	}
	
	public void setSpot(int a)
	{
		d[i]=a;
	}
	
	public void setfalg(int a)
	{
		flag[i]=a;
		i++;
	}
	
	
	public void writeStatusPic (int size) throws DocumentException, FileNotFoundException
	{
		Document document1 = new Document(PageSize.A4, 50, 50, 50, 50);
		PdfWriter writer1 = PdfWriter.getInstance(document1,new FileOutputStream("C:/TC/Report.pdf"));
		document1.open();
		Paragraph title1 = new Paragraph("Status Picture",FontFactory.getFont(FontFactory.COURIER,16, Font.BOLD, new CMYKColor(0, 255, 255,17)));
	      Paragraph paragraph1 = new Paragraph();
	      //paragraph1.setSpacingBefore(50);
	      title1.setAlignment(Element.ALIGN_CENTER);
	      paragraph1.add(title1);
	      
	      for(int i=0;i<10;i++)
		      paragraph1.add(Chunk.NEWLINE);
	      
		  paragraph1.add("  - Available Spot\n");
		  paragraph1.add("  - Spot Under Maintenance\n");
		  paragraph1.add("  - Spot Is Taken");
	      document1.add(paragraph1);
		
		 PdfContentByte canvas = writer1.getDirectContent();
	     canvas.saveState();
	     canvas.setColorFill(BaseColor.LIGHT_GRAY);
	     canvas.rectangle(110,550, 400, 200);
	     canvas.fillStroke();
	     canvas.restoreState();
	     
	     canvas.setColorFill(BaseColor.RED);
			canvas.rectangle(40,455, 10, 10);
			canvas.fillStroke();
			canvas.setColorFill(BaseColor.BLACK);
			canvas.rectangle(40,480, 10, 10);
			canvas.fillStroke();
			canvas.setColorFill(BaseColor.WHITE);
			canvas.rectangle(40,500, 10, 10);
			canvas.fillStroke();
	     
	        int i,j,k=135,m=580;
	        int f=0,l=0,n=0,e=0;
	        for(i=0;i<9;i++){
	        	for(j=0;j<size;j++){
	        		if(x[l]==i/3 && y[n]==j && d[e]==f)
	        		{
	        			if(flag[e]==1)
	        				canvas.setColorFill(BaseColor.BLACK);
	        			else
	        			canvas.setColorFill(BaseColor.RED);
	        			l++;
	        			n++;
	        			e++;
	        		}
	        		else
	        		canvas.setColorFill(BaseColor.WHITE);
        			canvas.rectangle(k,m, 10, 10);
       				canvas.fillStroke();
       				k=k+50;
       				}
	        
	        	k=135;
	        	if(f==2)
	        	{
	        	m=m+40;
	        	f=0;
	        	}
	        	else
	        	{
	        		f++;
	        		m=m+10;
	        	}
	        	}
	        document1.close(); 
	}
	
	

}
